<?php


class Drop {
    
    protected $x;
    protected $y;
    protected $length;
    protected $color;
    
    function __construct($x, $y) {
        $this->x = $x;
        $this->y = $y;
        $this->length = rand(5, 10); 
        $r = dechex(20+(sin($this->x)*235));
        $g = $r; //dechex(rand(0, 255));
        $b = $r;  //dechex(rand(0, 255));
        $r = strlen($r == 1) ? $r."0" : $r;
        $g = strlen($g == 1) ? $r."0" : $g; 
        $b = strlen($b == 1) ? $r."0" : $b;
        $this->color = $r.$g.$b;
        $this->x +=1;
    
    }

    public function draw() {
        //echo("px ".($this->x-10)." ".(pow((sin($this->y)-10),2)%500)." 000000\n");
        echo("px ".$this->x." ".(int)(500*abs(pow(2,cos($this->y))))." ".$this->color."\n");
    }   

    public function update() {
        $this->outOfCanvas();
        $this->y += 1;
        if ($this->y % 5 == 0)
            $this->x += 1;
    }

    public function outOfCanvas() {
        if($this->y > 500) {
            $this->x = rand(0, 800);
            $this->y = rand(0, 1000);
        }
    }
}

$drops = [];
for($i=0;$i<1;$i++) {
    $drops[] = new Drop(rand(0, 800), rand(0, 1000));
}


while(true) {
    foreach($drops as $drop) {
        $drop->update();
        $drop->draw();
    }
}
